#pragma once

#include "Protocol.hpp"
#include <iostream>

class Cal
{
public:
    Response Execute(Request& req)
    {
        //code: 0 表示成功
        Response resp(0, 0);
        switch(req.Oper())
        {
        case '+':
            resp.SetResult(req.X() + req.Y());
            break;
        case '-':
            resp.SetResult(req.X() - req.Y());
            break;
        case '*':
            resp.SetResult(req.X() * req.Y());
            break;
        case '/':
            if(req.Y() == 0)
            {
                //1:除零错误
                resp.SetCode(1);
            }
            else
            {
                resp.SetResult(req.X() / req.Y());
            }
            break;
        case '%':
            if(req.Y() == 0)
            {
                //2:mod 0 错误
                resp.SetCode(2);
            }
            else
            {
                resp.SetResult(req.X() % req.Y());
            }
            break;
        default:
            //非法操作
            resp.SetCode(3);
            break;
        }

        return resp;
    }
};